class Food {

}
class Fruit extends Food {

}
class Apple extends Fruit {

}
class Banana extends Fruit {

}
class Plate<T> { // 设置泛型
    private T data ;

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
public class tex3 {
    //通配符的上界的使用；
    public static void fun1(Plate<? extends Fruit> tmp){
        Fruit fruit=tmp.getData();
        System.out.println(fruit);
        //tmp.setData(new Apple());
    }
    public  static void main1(String[] args){
        Apple apple=new Apple();
        Banana banana=new Banana();
        Plate<Apple> plate1=new Plate<>();
        fun1(plate1);
        Plate<Banana> plate2=new Plate<>();
        fun1(plate2);
        plate1.setData(apple);
    }
    public static void fun2(Plate<? super Fruit> tmp){
        Object object=tmp.getData();
        System.out.println(object);
        tmp.setData(new Apple());
        tmp.setData(new Fruit());
        //tmp.setData(new Food());错误，
    }
    public static void main(String[] args){
        Plate<Apple> plate=new Plate<>();
        //fun2(plate);不允许传入Fruit的子类；
        Plate<Fruit> fruitPlate=new Plate<>();
        fun2(fruitPlate);//本身可以；
        Apple apple=new Apple();
        plate.setData(apple);

    }

}
